package com.ruoyi.langchain4j.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.langchain4j.assistant.XiaoZhiAgent;
import com.ruoyi.langchain4j.body.XiaoZhiChatFormBody;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @className: XiaoZhiController
 * @date: 2025-7-11 10:33
 * @description:
 */
@Slf4j
@Tag(name = "医疗-小智客服")
@RestController
@RequestMapping("/xiaozhi")
public class XiaoZhiController extends BaseController {


    @Autowired
    private XiaoZhiAgent xiaoZhiAgent;

    @Operation(summary = "对话")
    @PostMapping("/chat")
    public String chatList(@RequestBody XiaoZhiChatFormBody body) {
        log.info("开始对话userMessage:{}",body.getUserMessage());
        return xiaoZhiAgent.chat(body.getMemoryId(), body.getUserMessage());
    }

    @Operation(summary = "流式对话")
    @PostMapping(value = "/streamChat", produces = "text/stream;charset=utf-8")
    public Flux<String> streamChat(@RequestBody XiaoZhiChatFormBody body) {
        log.info("开始流式对话userMessage:{}",body.getUserMessage());
        Flux<String> stringFlux = xiaoZhiAgent.streamChat(body.getMemoryId(), body.getUserMessage());
        System.out.println(stringFlux);
        return stringFlux;
    }
}
